import axios from "axios";
import { dateFormat } from "../utils/helper";
// const imbedApi = axios.create({
//     // baseURL: END_POINT,
//     withCredentials: false,
//     timeout: 6000000,
//     headers: {
//       "Content-Type": "application/json;charset=utf-8",
//       Accept: "application/json",
//     },
//   });
//   this.imbedapi(666001002,"邮件发送").then(res => console.warn(res,"邮件发送"))

let newdate = new Date();
// 埋点接口，输入参数为 用户id，事件名
const imbedapi = (eid, tag = "") => {
  let datemanage = Date.parse(new Date()) + "";
  let mathdate = parseInt(datemanage) / 1000;
  // console.warn(datemanage.substr(0,datemanage.length - 3),"当前时间戳",datemanage,mathdate);
  console.warn(mathdate);
  // https://stat-dcs-dc-test.wanyol.com 测试
  // https://event.dc.oppomobile.com 正式
  return axios.post(
    "https://event.dc.oppomobile.com/stat/event",
    {
      // timeout: 1000,
      // headers: {
      //     "Content-Type": "application/json;charset=utf-8",
      //     Accept: "application/json",
      // },

      head: {
        ssoid:
          JSON.parse(localStorage.getItem("omail_userInfo")).jobNo ||
          "没有获取到ssoid",
        imei: "",
        model: "",
        osVersion: "",
        romVersion: "",
        androidVersion: "",
        sdkVersion: "",
        appVersion: "",
        appId: 20344,
        channel: "",
        access: "",
        region: "",
        brand: "",
        duid: "",
        ouid: "",
        guid: "",
        localId: "",
        postTime: mathdate,
      },
      body: {
        event: [
          {
            eventID: eid + "",
            eventTag: tag,
            eventTime: dateFormat(newdate, "yyyy-MM-dd hh:mm:ss"),
            duration: 0,
            eventCount: 1,
            appId: 20344,
            ssoid: JSON.parse(localStorage.getItem("omail_userInfo")).jobNo,
            appVersion: "",
          },
        ],
      },
    },
    {
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        Accept: "application/json",
      },
    }
  );
};
// 判断它是否是第一次操作
// 在加载页面获取token时发送一次 附带时间
export default imbedapi;
